package code

import (
	utils "gitee.com/ichub/goconfig/common/base/baseutils/stringutils"
	"gitee.com/ichub/gofactroy/common/ichubbase"
	buildfactroy2 "gitee.com/ichub/gofactroy/factroy/dbfactroy"
	"time"
)

type DtoFactroy struct {
}

// ReadTemplateServiceInterface
func (dto *DtoFactroy) buildDto(tableTool *buildfactroy2.DbFactroy) string {

	bs := buildfactroy2.InstFileFactroy.ReadTemplateDto()

	vars := make(map[string]interface{})
	vars["FileName"] = utils.Case2Camel(tableTool.Table) + "Dto.go"
	vars["Description"] = "接口" + utils.Case2Camel(tableTool.Table) + "Dto"
	vars["Author"] = tableTool.Author
	vars["DATETIME"] = time.Now().Format(ichubbase.FormatDateTime)

	vars["Model"] = utils.Case2Camel(tableTool.Table)
	vars["pkey"] = utils.Case2Camel(tableTool.Pkey)
	vars["pkeyType"] = tableTool.FindProtoType(tableTool.PkeyType)

	return utils.ParseTemplateString(string(bs), vars)

}

func (dto *DtoFactroy) Build(tool *buildfactroy2.DbFactroy) (dir, f, c string) {

	fbase := utils.Lcfirst(utils.Case2Camel(tool.Table))
	dir = buildfactroy2.InstFileFactroy.TransDir(buildfactroy2.Gendir_dto, fbase)

	f, c = fbase+"Dto.go", dto.buildDto(tool)
	buildfactroy2.InstFileFactroy.WriteFileModule(dir, f, c)

	return
}
